﻿@using Microsoft.AspNetCore.Identity
@using System.Security.Claims

<ul class="navbar-nav">
    @if (User.Identity?.IsAuthenticated ?? false)
    {
        var ci = (ClaimsIdentity)User.Identity;
        var trueName = ci.FindFirst("TrueName")?.Value;
        if (trueName is null)
        {
            trueName = User.Identity.Name;
        }
        var src = ci.FindFirst("Avatar")?.Value;
        if (string.IsNullOrEmpty(src))
        {
            src = "/images/guest.jpg";
        }
        <li class="nav-item">
            <a class="nav-link text-light" href="#"><img style="width:20px;height:20px" src="@src"> @trueName</a>
        </li>
        <li class="nav-item">
            <a class="nav-link text-light" asp-page="/Account/Logout"> 退出</a>
        </li>
    }
    else
    {
        <li class="nav-item">
            <a class="nav-link text-light" asp-page="/Account/Login">登录</a>
        </li>
    }
</ul>
